package cc.SSM.exceptions;

/**
 * Created by rongmc on 16/3/23.
 * xxx+xx+xxx (错误类型+业务类型+错误码)
 * 例如:500+00+001表示:
 * 500服务器端异常+01用户业务+001错误类型
 */
public enum UserExceptionEnum {

    USER_HAS_REGISTERED(Long.valueOf(50001001), "用户已经被注册"),
    ILLEGAL_USERNAME_OR_PWD(Long.valueOf(50001002),"您输入的用户名或者密码有误!"),
    USER_NULL(Long.valueOf(50001003),"用户不存在"),
    REPEAT_BINDING(Long.valueOf(50001004),"该手机号已被绑定"),
    CAPTCHA_ERROR(Long.valueOf(50001006),"验证码错误"),
    MOBILE_NOT_BIND(Long.valueOf(50001007),"手机号未绑定"),
    INVITE_CODE_ERROR(Long.valueOf(50001008),"邀请码不存在,注册失败");


    private Long code;
    private String description;

    private UserExceptionEnum(Long code, String description) {
        this.code = code;
        this.description = description;
    }

    public static UserExceptionEnum get(Long code) {
        if(code == null) {
            return null;
        } else {
            UserExceptionEnum[] arr$ = values();
            int len$ = arr$.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                UserExceptionEnum appResultCodeEnum = arr$[i$];
                if(appResultCodeEnum.getCode().equals(code)) {
                    return appResultCodeEnum;
                }
            }

            return null;
        }
    }

    public static boolean is(UserExceptionEnum appResultCodeEnum, Long code) {
        return appResultCodeEnum != null && code != null?appResultCodeEnum.getCode().equals(code):false;
    }

    public Long getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }
}
